package main;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Outputter {

	public void OutPut(ArrayList<String[]> output, String outFile, String inFile) {

		try {

				FileInputStream fis = new FileInputStream(inFile);
				DataInputStream ds = new DataInputStream(fis);
				BufferedReader br = new BufferedReader(new InputStreamReader(ds));
				
				String line = "";
				
				
				
				FileWriter fstream = new FileWriter(outFile);
				BufferedWriter out = new BufferedWriter(fstream);
				
				int i = 0;
			
				while((line = br.readLine()) != null){
					String[] tabs = line.split("\\t");

					
					if(tabs.length == 6 && isAlpha(tabs[4])){	

								String compare = output.get(i)[0];

								if(tabs[3].equals(compare)){
									String outs = "";
									for(int j = 0; j < tabs.length -1 ; j++){
										outs += tabs[j] + "\t";
									}
									
									outs += output.get(i)[2] + "\n";

									out.write(outs);
									
									
									
								}else{
									out.write(line + "\n");
								}
								i++;
							
							
						}else{
							out.write(line + "\n");
						}
						
					
				}
				
						

				
			br.close();
			out.close();
		} catch (Exception e) {
			System.err.println("Error: " + e.getMessage());
		}

	}
	
	   private  boolean isAlpha(String name) {
		    return name.matches("[a-zA-Z]+");
	}

}
